//! @file   lc_multi_reader_lock.h
//! @brief  
//! @author Sayan Chaliha
//! @date   September, 2011
//!
//! 
#ifndef _LC_MULTI_READER_LOCK_H
#define _LC_MULTI_READER_LOCK_H

#include "libcyan_internal.h"
#include "lc_types.h"
#include "lc_object.h"

namespace cyan {
  class CYAN_API MultiReaderLock : public Object {
  public:
    MultiReaderLock();
    virtual ~MultiReaderLock();

    void readLock();
    void writeLock();
    Bool tryReadLock();
    Bool tryWriteLock();
    void unlock();

  private:
    MultiReaderLock(const MultiReaderLock&);
    MultiReaderLock& operator =(const MultiReaderLock&);

    MultiReaderLockType lock_;
  };

  class CYAN_API WriteGuard {
  public:
    WriteGuard(MultiReaderLock& lock);
    virtual ~WriteGuard();

  private:
    WriteGuard();
    WriteGuard(WriteGuard&);
    WriteGuard& operator =(const WriteGuard&);

    MultiReaderLock* lock_;
  };

  class CYAN_API ReadGuard {
  public:
    ReadGuard(MultiReaderLock& lock);
    virtual ~ReadGuard();

  private:
    ReadGuard();
    ReadGuard(ReadGuard&);
    ReadGuard& operator =(const ReadGuard&);

    MultiReaderLock* lock_;
  };
}

#endif /* _LC_MULTI_READER_LOCK_H */
